package com.ruoyi.system.untils;

import io.minio.MinioClient;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

/**
 * 单例模式,minio客户端工具类
 */
@Component
public class MinioClientUtil {

    @Value(value = "${minio.url}")
    private String url;

    @Value(value = "${minio.access-key}")
    private String accessKey;

    @Value(value = "${minio.secret-key}")
    private String secretKey;
    private MinioClient minioClient;

    /**
     * 私有构造器
     */
    private MinioClientUtil() {

    }

    public MinioClient getMinioClient() {
        if (minioClient == null) {
            initClient();
        }
        return minioClient;
    }

    public void initClient() {
        minioClient = MinioClient.builder().endpoint(url).credentials(accessKey, secretKey).build();
    }

}
